package com.ky.manage.ui;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

/**
 * 设置间距
 */
public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
    private int space, spanCnt;

    public SpaceItemDecoration(int space, int spanCnt) {
        this.space = space;
        this.spanCnt = spanCnt;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        outRect.left = space;
        outRect.bottom = space;
        if (parent.getChildLayoutPosition(view) %spanCnt==0) {
            outRect.left = 0;
        }
    }
}
